<div class="content-wrapper">

    <section class="content-header">
        <?php echo $this->partial('layout/breadcrumb'); ?>

        <h1 class="pull-right" id="dberp-menu-top">
            <?php echo $this->HelpUrl('salesOrderReturnList'); ?>
        </h1>

    </section>

    <section class="content">
        <?php echo $this->partial('layout/messages'); ?>

        <div class="row">
            <div class="col-xs-12">
                <div class="box erp-box">

                    <div class="box-body table-responsive no-padding">
                        <table class="table table-hover">
                            <thead>
                            <tr class="erp-bg-thead">
                                <th width="19%"><?php echo $this->translate('销售单号'); ?>-<?php echo $this->translate('订单数：').$this->orderList->getTotalItemCount(); ?></th>
                                <th width="10%"><?php echo $this->translate('发货单号'); ?></th>
                                <th width="19%"><?php echo $this->translate('客户'); ?>/<?php echo $this->translate('联系人'); ?>/<?php echo $this->translate('联系电话'); ?></th>
                                <th width="10%"><?php echo $this->translate('退货金额'); ?></th>
                                <th width="6%"><?php echo $this->translate('状态'); ?></th>
                                <th width="16%"><?php echo $this->translate('时间'); ?></th>
                                <th width="15%"><?php echo $this->translate('操作'); ?></th>
                            </tr>
                            <?php
                            $sForm = $this->searchForm;
                            $sForm->prepare();
                            $sForm->get('return_state')->setEmptyOption('选择');
                            ?>
                            <?php echo $this->form()->openTag($sForm); ?>
                            <tr>
                                <td>
                                    <p>
                                        <?php echo $this->formElement($sForm->get('sales_order_sn')); ?>
                                        <?php echo $this->formElementErrors($sForm->get('sales_order_sn'), ['class'=>'error-message']);?>
                                    </p>
                                    <p>
                                        <?php echo $this->formElement($sForm->get('sales_goods_sn')); ?>
                                        <?php echo $this->formElementErrors($sForm->get('sales_goods_sn'), ['class'=>'error-message']);?>
                                    </p>
                                </td>
                                <td>
                                    <?php echo $this->formElement($sForm->get('send_order_sn')); ?>
                                    <?php echo $this->formElementErrors($sForm->get('send_order_sn'), ['class'=>'error-message']);?>
                                </td>
                                <td>
                                    <p>
                                        <?php echo $this->formElement($sForm->get('customer_id')); ?>
                                        <?php echo $this->formElementErrors($sForm->get('customer_id'), ['class'=>'error-message']);?>
                                    </p>
                                    <p>
                                        <?php echo $this->formElement($sForm->get('customer_contacts')); ?>
                                        <?php echo $this->formElementErrors($sForm->get('customer_contacts'), ['class'=>'error-message']);?>
                                    </p>
                                    <p>
                                        <?php echo $this->formElement($sForm->get('customer_phone')); ?>
                                        <?php echo $this->formElementErrors($sForm->get('customer_phone'), ['class'=>'error-message']);?>
                                    </p>
                                </td>
                                <td>
                                    <p>
                                        <?php echo $this->formElement($sForm->get('start_amount')); ?>
                                    </p>
                                    <div>
                                        <?php echo $this->formElement($sForm->get('end_amount')); ?>
                                    </div>
                                    <?php echo $this->formElementErrors($sForm->get('start_amount'), ['class'=>'error-message']);?>
                                    <?php echo $this->formElementErrors($sForm->get('end_amount'), ['class'=>'error-message']);?>
                                </td>
                                <td>
                                    <?php echo $this->formElement($sForm->get('return_state')); ?>
                                    <?php echo $this->formElementErrors($sForm->get('return_state'), ['class'=>'error-message']);?>
                                </td>
                                <td>
                                    <div class="input-group" style="margin-bottom: 5px;">
                                        <span class="input-group-addon" style="padding: 0;">
                                            <?php echo $this->formElement($sForm->get('time_type')); ?>
                                        </span>
                                        <?php echo $this->formElement($sForm->get('start_time')); ?>
                                    </div>
                                    <div class="input-group">
                                        <span class="input-group-addon" style="font-size: 13px;padding-left: 18px;padding-right: 18px;"><?php echo $this->translate('同上'); ?></span>
                                        <?php echo $this->formElement($sForm->get('end_time')); ?>
                                    </div>
                                    <?php echo $this->formElementErrors($sForm->get('start_time'), ['class'=>'error-message']);?>
                                    <?php echo $this->formElementErrors($sForm->get('end_time'), ['class'=>'error-message']);?>
                                </td>
                                <td>
                                    <button type="submit" class="btn btn-info btn-sm"><i class="fa fa-search"></i></button>
                                    <?php if(!empty(array_filter($sForm->getData()))) { ?>
                                        <a href="<?php echo $this->url('sales-order-return');?>" class="btn btn-default btn-sm"><i class="fa fa-reply"></i></a>
                                    <?php } ?>
                                </td>
                            </tr>
                            <?php echo $this->form()->closeTag(); ?>
                            </thead>

                            <?php if($this->orderList) foreach ($this->orderList as $order) { ?>
                                <tr>
                                    <td><?php echo $this->escapeHtml($order->getSalesorderSn()); ?></td>
                                    <td><?php echo $this->escapeHtml($order->getSalesSendOrderSn()); ?></td>
                                    <td>
                                        <?php echo $this->escapeHtml($order->getOneSalesOrder()->getOneCustomer()->getCustomerName()); ?><br>
                                        <small><?php echo $this->escapeHtml($order->getOneSalesOrder()->getCustomerContacts()); ?></small><br>
                                        <small><?php echo $this->escapeHtml($order->getOneSalesOrder()->getCustomerPhone()); ?></small>
                                    </td>
                                    <td><?php echo $this->erpCurrencyFormat($order->getSalesOrderReturnAmount());?></td>
                                    <td><?php echo $this->salesHelper()->salesOrderReturnState($order->getReturnState(), 2); ?></td>
                                    <td>
                                        <?php if ($order->getOneSalesOrder()->getReturnTime() > 0) { ?><span class="badge bg-blue" title="<?php echo $this->translate('退货中'); ?>"><?php echo $this->translate('退货中'); ?></span> <small><?php echo date("Y-m-d H:i:s", $order->getOneSalesOrder()->getReturnTime());?></small><?php } ?>
                                        <?php if ($order->getOneSalesOrder()->getReturnFinishTime() > 0) { ?><br><span class="badge bg-blue" title="<?php echo $this->translate('已退货'); ?>"><?php echo $this->translate('已退货'); ?></span> <small><?php echo date("Y-m-d H:i:s", $order->getOneSalesOrder()->getReturnFinishTime());?></small><?php } ?>
                                    </td>
                                    <td>
                                        <a href="<?php echo $this->url('sales-order-return',
                                            ['action'=>'view', 'id'=>$order->getSalesOrderReturnId()]); ?>" class="btn btn-xs btn-info"><i class="fa fa-info-circle"></i> <?php echo $this->translate('查看'); ?></a>
                                        <?php if($order->getReturnState() == -1) { ?>
                                            <a href="<?php echo $this->url('sales-order-return',
                                                ['action'=>'finish', 'id'=>$order->getSalesOrderReturnId()], ['query' => ['qToken' => $this->common()->getCsrfValue()]]); ?>" class="btn btn-xs btn-success"><i class="fa fa-check"></i> <?php echo $this->translate('退货完成'); ?></a>
                                            <a href="<?php echo $this->url('sales-order-return',
                                                ['action'=>'cancel', 'id'=>$order->getSalesOrderReturnId()], ['query' => ['qToken' => $this->common()->getCsrfValue()]]); ?>" class="btn btn-xs btn-warning"><i class="fa fa-remove"></i> <?php echo $this->translate('取消退货'); ?></a>
                                        <?php } ?>

                                    </td>
                                </tr>
                            <?php } ?>
                        </table>
                    </div>
                    <div class="box-footer clearfix">
                        <?php echo $this->paginationControl($this->orderList, 'Sliding', 'layout/page', ['route' => 'sales-order-return']); ?>
                    </div>
                </div>

            </div>
        </div>

    </section>
</div>
<script type="text/javascript">
    laydate.render({elem: '#start_time'});
    laydate.render({elem: '#end_time'});
</script>